<template>
  <el-container style="height: 100vh; border: 1px solid #eee">
    <el-header style="text-align: right; font-size: 12px">
      <el-dropdown @command="handleCommand">
        <i class="el-icon-setting" style="margin-right: 15px"></i>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span>{{ user.username }}</span>
    </el-header>


    <el-container>

      <el-aside width="200px" height="100vh" style="background-color: rgb(238, 241, 246)">
        <el-menu router default-active="/student">
          <el-submenu index="1">
            <template slot="title"><i class="el-icon-message"></i>学生管理</template>
            <el-menu-item-group>
              <el-menu-item index="/student">学生信息管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title"><i class="el-icon-menu"></i>宿舍管理</template>
            <el-menu-item-group>
              <el-menu-item index="/room">宿舍信息管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>
<style>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>

<script>
export default {
  data() {
    return {
      user: {}
    }
  },
  methods: {
    handleCommand(command) {
      if (command == 'a') {
        // 清空登录，并且回到登录页面
        localStorage.removeItem("user");
        this.$router.push("/");
      }
    }
  },
  created() {
    this.user = JSON.parse(localStorage.getItem("user"));
  }
};
</script>